﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WMS.FC.Domain.PersistenceObject.Business;
using WMS.FC.Infrastructure.Common;

namespace WMS.FC.Infrastructure.POConfig.Business
{
    public class TechnologyFormulaParamConfig : POBaseConfig<TechnologyFormulaParamPO>
    {
        public override void InitializeData(EntityTypeBuilder<TechnologyFormulaParamPO> builder)
        {
        }

        public override void MapColumn(EntityTypeBuilder<TechnologyFormulaParamPO> builder, ref int index)
        {
            builder.HasComment("工艺公式参数表");
            builder.Property(entity => entity.TechnologyFormulaId).ConfigColumn("TECHNOLOGY_FORMULA_ID", "工艺公式ID").HasColumnOrder(index++);
            builder.Property(entity => entity.Code).ConfigColumn("CODE", "编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.TargetTechnologyProcessCode).ConfigColumn("TARGET_TECHNOLOGY_PROCESS_CODE", "目标工艺工序编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.TargetStep).ConfigColumn("TARGET_STEP", "目标工步").HasColumnOrder(index++);
            builder.Property(entity => entity.TargetParamCode).ConfigColumn("TARGET_PARAM_CODE", "目标结果数据编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.WarehouseCode).ConfigColumn("WAREHOUSE_CODE", "仓库编码", 50, true).HasColumnOrder(index++);
        }

        public override void MapIndex(EntityTypeBuilder<TechnologyFormulaParamPO> builder)
        {
            builder.HasIndex(entity => new { entity.TechnologyFormulaId, entity.Code, entity.WarehouseCode }).HasDatabaseName($"UN_{TableName}_1").IsUnique();
        }
    }
}
